home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.internetmci.com!xmission!inteleNET!usenet
- From: langj@jcave.com (Jonathan Lang)
- Newsgroups: comp.lang.c++
- Subject: Re: Using typedefs in templates (not a FAQ)
- Date: Sat, 09 Mar 1996 08:13:32 GMT
- Organization: inteleNET Internet Services
- Message-ID: <4hrb00$8g8@vodka.intele.net>
- References: <4higv6$7ih@news.hal.com>
- NNTP-Posting-Host: p142.jcave.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- spike@hal.com (Spike White) wrote:
-
- >I want to typedef a new type based on the types of the formal template
- >parameter list. Is that possible?
-
- >Something like:
-
- >template <class KEY, class NODEDATA>
- >class Tree {
- >public:
- > typedef int (*pfid)(NODEDATA);
- > typedef int (*pfi2c)(const KEY, const NODEDATA);
- >...
- > pfi2c pfi_compare; // my compare function
- >...
- > int trav(pfid); // perform the function on each node
- >...
- >}
-
- This looks valid to me...
-
- >Obviously, I could "uglify" my header file and C file by replacing the
- >typedefs w/ the literal expansion, but I'd rather not do that. And I
- >can't figure out a macro that would work.
-
- >I've also considered passing these new types when instantiating, as
- >the 3rd and 4th formal parameters. How would that be done? Would it be
- >something like:
-
- >template <class KEY, class NODEDATA, class int (*pfid)(NODEDATA), ... >
- >{
- >...
- >}
-
- No good; a template 'class parameter' is the keyword 'class' followed
- by an identifier; no method for specifying further exists in the
- template declaration. However, your first suggestion compiles fine on
- my system.
-
- >--
- >Spike White | spike@hal.com | Biker Nerds
- >HaL Software Systems | '87 BMW K75S, DoD #1347 | From HaL
- >Austin, TX | http://www.halsoft.com/users/spike/index.html
- >Disclaimer: HaL, want me to speak for you? No, Dave...
-
- -- Jonathan Lang (langj@jcave.com)
-
-